package com.example.administrator.capital.mine;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.capital.R;
import com.example.administrator.capital.base.BaseBackFragment;
import com.example.administrator.capital.consult.CompanyNoticeFragment;
import com.example.administrator.capital.consult.ConsultFragment;
import com.example.administrator.capital.consult.RecommendFragment;
import com.example.administrator.capital.mine.investment.AllInvestmentFragment;
import com.example.administrator.capital.mine.investment.CompleteInvestmentFragment;
import com.example.administrator.capital.mine.investment.LoanInvestmentFragment;
import com.example.administrator.capital.mine.investment.RefundInvestmentFragment;
import com.example.administrator.capital.mine.investment.TuiKuanFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import tablayout.SlidingTabLayout;

/**
 * A simple {@link Fragment} subclass.
 * 投资记录
 */
public class InvestmentRecordFragment extends BaseBackFragment{
    @BindView(R.id.tab_layout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.view_pager)
    ViewPager mViewPager;
    Unbinder unbinder;
    private TextView mBack;
    private final String[] mTitles = {
            "全部", "出借中","还款中","已完成","已退款"
    };
    private MyPagerAdapter mAdapter;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    public InvestmentRecordFragment() {
        // Required empty public constructor
    }
    public static InvestmentRecordFragment newInstance() {
        Bundle args = new Bundle();
        InvestmentRecordFragment fragment = new InvestmentRecordFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_investment_record, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }
    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        mFragments.add(AllInvestmentFragment.newInstance());
        mFragments.add(LoanInvestmentFragment.newInstance());
        mFragments.add(RefundInvestmentFragment.newInstance());
        mFragments.add(CompleteInvestmentFragment.newInstance());
        mFragments.add(TuiKuanFragment.newInstance());
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setViewPager(mViewPager);
    }
    @Override
    protected void initView(View view) {
        super.initView(view);
        mBack = view.findViewById(R.id.app_title_back);
        mAdapter = new MyPagerAdapter(getChildFragmentManager());
    }
    @Override
    protected void setListener() {
        super.setListener();
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                _mActivity.onBackPressed();
            }
        });
    }
    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }
        @Override
        public int getCount() {
            return mTitles.length;
        }
        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }
        @Override
        public android.support.v4.app.Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
